<template>
  <div>
    <!--主盒子-->
    <view>
      <swiper :images="images" />
    </view>
  <div class="container2">
    <scroll-view class="i-tabs i-tabs-scroll" scroll-x="">
      <div class='nav_left clearfix'>
        <div class='nav_left_items' :class="[curNav==0 ? 'active':'']" @click="switchRightTab"  data-id="0">全部</div>
        <div v-for="(item,key) in list2" :key="key2" class='nav_left_items' :class="[curNav==item.id ? 'active':'']" @click="switchRightTab"  :data-id="item.id">{{item.name}}</div>
      </div>
    </scroll-view>
      <div class="nav_right">
<!--        <div v-if="curNav==0">-->
<!--          <div class="nav_right_items clearfix" v-for="(item,key) in list" :key="key" @click="goContent(item.id)">-->
<!--            <image :src="item.img" mode="widthFix" class="img2"></image>-->
<!--            <div class="frword">-->
<!--              <text class="name">{{item.name}}</text>-->
<!--              <div class="promore">查看详情</div>-->
<!--&lt;!&ndash;              <div class="content2" v-html="item.info">&ndash;&gt;-->
<!--&lt;!&ndash;              </div>&ndash;&gt;-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
        <div  class="nav_right_items" v-for="(item,key) in list" :key="key" @click="goContent(item.id)">
          <image :src="item.img" mode="widthFix" class="img2"></image>
          <div class="frword">
            <text class="name">{{item.name}}</text>
            <div class="promore">查看详情</div>
<!--            <div class="content2" v-html="item.info">-->
<!--            </div>-->
          </div>
        </div>
        <i-load-more :tip="loadingtip" :loading="loadingtrue" />
      </div>
    </div>
  </div>
</template>
<script>
  import swiper from "@/components/swiper";
  export default {
    components: { swiper },
    name: "",
    data() {
      return {
        images: [
          {
            url:
              "https://eztw.com.cn/static/uploads/banner/3f022b688655910b42dd0b0c0079a70b.jpg",
          }
        ],
        curNav:0,
        list: [],
        list2: [],
        loadingtip:'',
        loadingtrue:true,
        page: 1,
        cateid:0,
        total_page: 0,
        current: 'tab1',
        fcateid:''
      }
    },
    methods: {
      switchRightTab:function(e){
        var id =e.target.dataset.id
        // console.log(id)
        this.curNav=id
        this.cateid=id
        this.page=1
        this.loadingtip='',
        this.loadingtrue=true,
        this.requestData();
      },
      requestData() {
        wx.showNavigationBarLoading()
        const that = this;
        const api = 'https://eztw.com.cn/appallproget';
        wx.request({
          url: api, //仅为示例，并非真实的接口地址
          data: {
            page: that.page,
            cateid:that.cateid
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            wx.stopPullDownRefresh()
            wx.hideNavigationBarLoading()
            // const data = res.data
            console.log(res.data);
            console.log('请求成功');
            if (that.page > 1) {
              that.list.push(...res.data.result)
              console.log(that.list)
            }
            else {
              console.log(res.data)
              that.list = res.data.result
            }
            if(res.data.total_page==0)
            {
              console.log(res.data.total_page);
              that.loadingtrue=false
              that.loadingtip='暂无数据'
              console.log('数据加载完了')
            }
            if(res.data.total_page==1)
            {
              console.log(res.data.total_page);
              that.loadingtrue=false
              that.loadingtip='暂无数据'
              console.log('数据加载完了')
            }
            that.total_page = res.data.total_page
//             that.list = res.data;
            that.fcateid=res.data.fcateid

          }
        })
      },
      requestData2() {
        wx.showNavigationBarLoading()
        const that = this;
        // console.log(that)
        const api = 'https://eztw.com.cn/appallpro';
        wx.request({
          url: api, //仅为示例，并非真实的接口地址
          data: {
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success: function (res) {
            wx.hideNavigationBarLoading()
            // console.log(res.data)
            that.list2 = res.data;
          }
        })
      },
      goContent(id,fcateid) {
        // console.log(aid)
        const that = this;
        console.log(that.fcateid);
        if(that.fcateid==null||that.fcateid==0)
        {
          const url = '../proscontent/main?id=' + id;
          wx.navigateTo({url});
        }
        else{
          const url = '../prolist2/main?id=' + id;
          wx.navigateTo({url});
        }
      },

    },
    /*生命周期函数*/
    onShow(){

    },
    mounted(){
      this.requestData();
      this.requestData2();

    },
    onReachBottom() {
      if (this.page >=this.total_page) {
        this.loadingtrue=false
        this.loadingtip='暂无数据'
        console.log('数据加载完了')
      }
      else {
        console.log('开始加载数据')
        this.page = this.page + 1
        console.log(this.page)
        this.requestData();
      }
    },
    onPullDownRefresh() {
      console.log('下拉刷新')
      this.loadingtrue=true
      this.loadingtip='正在加载'
      this.page = 1
      this.requestData()

    },

  }
</script>
<style scoped>
  .info{
    width: 90%;
    margin:10px auto;
  }
  page{
    background: #f5f5f5;
  }
  .promore{
    width:100px;
    height: 30px;
    line-height: 30px;
    background: #005bac;
    text-align: center;
    color: #ffffff;
    font-size: 14px;
    border-radius: 20px;
    margin-top: 30px;
    -webkit-box-shadow: 0 3px 15px rgba(168,168,168,.5);
    box-shadow: 0 3px 15px rgba(168,168,168,.5);
  }
  .container2 {
    width: 100%;
    height: 100%;
    background-color: #fff;
  }.nav_left{
       width: 100%;
       /*overflow-x: scroll;*/
       display: -webkit-box;
       display: flex;
       -webkit-flex-wrap:nowrap;
       flex-wrap:nowrap;
       -webkit-justify-content:space-between;
       justify-content:space-between;

   }
  .nav_left .nav_left_items{
    padding: 20px 3%;
    border-bottom: 1px solid #dedede;
    font-size: 14px;
    -webkit-flex:1 0 auto;
    flex:1 0 auto;
  }
  ::-webkit-scrollbar {display:none}
  .nav_left .nav_left_items.active{
    background: #fff;
    color: #005bac;
    border-bottom: 2px solid #005bac;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  .nav_right{
    width: 100%;
    height: auto;
    min-height: 100%;
    padding: 10px 10px 10px 10px;
    box-sizing: border-box;
    background: #f1efef;
  }
  .nav_right .nav_right_items{
    width:95%;
    padding:0 2.5%;
    background: #fff;
    align-items: center;
    flex-wrap:wrap;
    display: -webkit-flex;
    display: flex;
    flex-direction:column;
    margin:0 auto;
    display: inline-block;
    text-align: center;
  }
  /*.nav_right .nav_right_items image{*/
  /*  width:70%;*/
  /*  height: 70%;*/
  /*  margin-top: 15px;*/
  /*  border-radius: 40%;*/
  /*  display: block;*/
  /*  margin:0 auto;*/
  /*}*/
  .nav_right .nav_right_items text{
    font-size:12px;
  }
  .nav_right .nav_right_items .img2{
    width: 40%;
    float: left;
    padding:10px 0;
  }
  .nav_right .nav_right_items .frword{
    width: 55%;
    float: right;
    text-align: left;
  }
  .nav_right .nav_right_items .frword text{

    font-size: 14px;
    font-weight: normal;
    color: #333;
    display: block;
    margin-top: 15px;
    line-height: 20px;

  }
  .nav_right .nav_right_items .frword .content2{
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    color : #6c6b6b;
    font-size: 14px;
    line-height: 20px;
    margin-top: 10px;
    text-overflow: ellipsis;
    overflow: hidden;
  }
</style>
